package com.pn.taikao.service.impl;

import com.pn.taikao.entity.CheatingRecord;
import com.pn.taikao.mapper.CheatingRecordMapper;
import com.pn.taikao.service.CheatingRecordService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CheatingRecordServiceImpl implements CheatingRecordService {

    private final CheatingRecordMapper cheatingRecordMapper;

    public CheatingRecordServiceImpl(CheatingRecordMapper cheatingRecordMapper) {
        this.cheatingRecordMapper = cheatingRecordMapper;
    }

    @Override
    public void recordCheating(Long examId, String behaviorType, Integer count, LocalDateTime behaviorTime) {
        CheatingRecord record = new CheatingRecord();
        record.setExamId(examId);
        record.setBehaviorType(behaviorType);
        record.setBehaviorCount(count != null ? count : 1);
        record.setBehaviorTime(behaviorTime != null ? behaviorTime : LocalDateTime.now());
        record.setCreateTime(LocalDateTime.now());
        cheatingRecordMapper.insert(record);
    }

    @Override
    public List<CheatingRecord> getByExamId(Long examId) {
        return cheatingRecordMapper.selectByExamId(examId);
    }

    @Override
    public List<CheatingRecord> getByExamIdAndType(Long examId, String behaviorType) {
        return cheatingRecordMapper.selectByExamIdAndType(examId, behaviorType);
    }
}


